<?php

namespace app\modules\admin\controllers;

use app\modules\admin\models\AdminUser;
use yii\web\Controller;

/**
 * Default controller for the `admin` module
 */
class LoginController extends Controller
{
    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex()
    {
        $model = new AdminUser();
        $model->scenarios('login');
        if (\Yii::$app->request->isPost && $model->load(\Yii::$app->request->post()) && $model->login()) {
            $this->redirect(['index/index']);
        } else {
            return $this->renderPartial("login", ['model' => $model]);
        }
    }

    public function actionLogout()
    {
        \Yii::$app->user->logout();
        $this->redirect(['login/index']);
    }

}
